-- takes a while to run
import Primes
import Data.List
circularPrimes = [x | x <- [1..999999], isPrime x, isCircularPrime x]

rots' :: [a] -> Int -> [[a]]
rots' xs 0 = []
rots' (x:xs) n = newRot : (rots' newRot $ n-1)
                 where newRot = xs ++ [x]

rots :: [a] -> [[a]]
rots xs = rots' xs $ length xs

isCircularPrime :: Integer -> Bool
isCircularPrime x = isCircularPrime' $ map (read) $ rots (show x)

isCircularPrime' :: [Integer] -> Bool
isCircularPrime' [] = True
isCircularPrime' (x:xs)
                 | isPrime x = isCircularPrime' xs
                 | otherwise = False

main = length circularPrimes